package com.jinlejia.erp.ui.mine.actual;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ActivityMyActualBinding;

/**
 * 我的实勘（activity）
 */

public class ActualSurveyActivity extends AppCompatActivity {


    private FragmentManager fm;
    private FragmentTransaction ft;
    private int segmentIndex = 0;

    private ActivityMyActualBinding binding;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_my_actual);
        binding.setEvent(this);
        initView();
    }

    /**
     * 初始化视图
     */
    private void initView() {
        fm = getSupportFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.content, new ActualSellingFragment());
        ft.commitAllowingStateLoss();

        binding.segmentControl.setOnSegmentControlClickListener(index -> {
            segmentIndex = index;
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            switch (index) {
                case 0:
                    ft.replace(R.id.content, new ActualSellingFragment());
                    ft.commitAllowingStateLoss();
                    break;
                case 1:
                    ft.replace(R.id.content, new ActualRentFragment());
                    ft.commitAllowingStateLoss();
                    break;
                default:
                    break;
            }
        });
    }

    public void onClick(View view) {
        finish();
    }
}
